<template>
  <div class="tools-panel flex-between-center">
    <div class="flex-between-center">
      <!-- 1 挂断 -->
      <div class="tools-item">
        <div class="tools_item">
          <img
            :src="icon1"
            class="tools_item_leftImg w-60 h-60"
            alt=""
            @click="btn_HangUp"
          />
          <div class="tools_item_leftWord">挂断</div>
        </div>
        <div class="tools_item_right">
          <img :src="split" class="w-30 tools_item_rightImg" alt="" />
        </div>
      </div>

      <!-- 2 示忙 -->
      <div class="tools-item">
        <div class="tools_item">
          <img
            :src="icon2"
            class="tools_item_leftImg w-60 h-60"
            alt=""
            @click="btn_Busy"
          />
          <div class="tools_item_leftWord">示忙</div>
        </div>
        <div class="tools_item_right">
          <img :src="split" class="w-30 tools_item_rightImg" alt="" />
        </div>
      </div>

      <!-- 3 示闲 -->
      <div class="tools-item">
        <div class="tools_item">
          <img
            :src="icon3"
            class="tools_item_leftImg w-60 h-60"
            alt=""
            @click="btn_Idle"
          />
          <div class="tools_item_leftWord">示闲</div>
        </div>
        <div class="tools_item_right">
          <img :src="split" class="w-30 tools_item_rightImg" alt="" />
        </div>
      </div>

      <!-- 4 外呼 -->
      <div class="tools-item">
        <div class="tools_item">
          <img :src="icon4" class="tools_item_leftImg w-60 h-60" alt="" />
          <div class="tools_item_leftWord">外呼</div>
        </div>
        <div class="tools_item_right">
          <img :src="split" class="w-30 tools_item_rightImg" alt="" />
        </div>
      </div>

      <!-- 5 内呼 -->
      <div class="tools-item">
        <div class="tools_item">
          <img :src="icon5" class="tools_item_leftImg w-60 h-60" alt="" />
          <div class="tools_item_leftWord">内呼</div>
        </div>
        <div class="tools_item_right">
          <img :src="split" class="w-30 tools_item_rightImg" alt="" />
        </div>
      </div>

      <!-- 6 转外线 -->
      <div class="tools-item">
        <div class="tools_item">
          <img :src="icon6" class="tools_item_leftImg w-60 h-60" alt="" />
          <div class="tools_item_leftWord">转外线</div>
        </div>
        <div class="tools_item_right" v-if="isSoundRecording">
          <img :src="split" class="w-30 tools_item_rightImg" alt="" />
        </div>
      </div>

      <!-- 7 录音 -->
      <div class="tools-item" v-if="isSoundRecording">
        <div class="tools_item">
          <img
            :src="icon7"
            class="tools_item_leftImg w-60 h-60"
            alt=""
            @click="plays"
          />
          <div class="tools_item_leftWord">{{ soundRecordingType }}</div>
        </div>
        <!-- <div class="tools_item_right">
          <img :src="split" class="w-30 tools_item_rightImg" alt="">
        </div> -->
        <div class="soundRecording">
          <audio
            :src="soundRecordingUrl"
            controls
            @pause="is_stop = true"
            @play="is_stop = false"
            ref="audio"
          ></audio>
        </div>
      </div>

      <!-- 8 -->
      <div class="login">
        <el-button type="warning" @click="Login()">登录</el-button>
      </div>
    </div>
    <div>
      <span class="color-white">当前状态：</span
      ><span class="color-green">{{ currentState }}</span>
    </div>

    <NumberDialog
      :dialogVisible="dispatchImageDialogVisible"
      @closeDialog="dispatchImageDialogVisible = false"
    />
  </div>
</template>

<script>
import icon1 from "@/assets/tools/icon1.png";
import icon2 from "@/assets/tools/icon2.png";
import icon3 from "@/assets/tools/icon3.png";
import icon4 from "@/assets/tools/icon4.png";
import icon5 from "@/assets/tools/icon5.png";
import icon6 from "@/assets/tools/icon6.png";
import icon7 from "@/assets/tools/icon7.png";
import split from "@/assets/tools/split.png";
import NumberDialog from "@/views/casedeal/components/numberDialog";
import $ from "@/utils/webSocket/jquery-1.11.1.js";
import WebSocktInterface from "@/utils/webSocket/WebSocketHelper.js";
import VoiceInterfaceObject from "@/utils/webSocket/PhoneScript.js";
// import "@/utils/webSocket/layer.js";
export default {
  data() {
    return {
      icon1,
      icon2,
      icon3,
      icon4,
      icon5,
      icon6,
      icon7,
      split,
      dispatchImageDialogVisible: false,
      // 当前状态
      currentState: "空闲",
      dialogVisible: false,
      soundRecordingUrl: require("@/assets/bgm/xixi.mp3"),
      is_stop: true,
      soundRecordingType: "录音播放",
      duration: 0, //录音时长
      timer: null,
      isSoundRecording: false,
    };
  },
  components: {
    NumberDialog,
  },
  methods: {
    handleClose() {
      this.$emit("closeDialog");
      //   this.clearData();
    },
    Login() {
      this.dispatchImageDialogVisible = true;
    },
    initData() {},

    // 挂断电话
    btn_HangUp() {
      VoiceInterfaceObject.HangUp();
    },

    // 示忙
    btn_Busy() {
      VoiceInterfaceObject.SetBusy();
    },

    // 示闲
    btn_Idle() {
      VoiceInterfaceObject.SetIdle();
    },

    //播放暂停控制
    plays() {
      if (this.is_stop) {
        if (this.duration == 0) {
          this.duration = parseInt(this.$refs.audio.duration);
        }
        this.$refs.audio.play();
        this.soundRecordingType = "正在播放";
        this.timer = setInterval(() => {
          this.duration--;
          if (this.duration == 0) {
            this.soundRecordingType = "播放结束";
            clearInterval(this.timer);
          }
        }, 1000);
      } else {
        this.$refs.audio.pause();
        this.soundRecordingType = "暂停播放";
        clearInterval(this.timer);
      }
    },
  },
  created() {
    this.$bus.$on("soundRecording", (data) => {
      this.soundRecordingUrl = data.videoUrl;
      this.isSoundRecording = data.type;
    });

    // 获取当前页面的地址
    // let address = location.href.substr(location.href.indexOf('#')+1,location.href.length);
    // console.log(address)
  },
};
</script>

<style lang="scss" scoped>
.tools-panel {
  width: 100%;
  height: 90px;
  background: url(../../../assets/tools/tools_bg.png) no-repeat left -1px center;
  background-size: calc(100% + 2px) 90px;
  padding: 0px 30px;
  img {
    cursor: pointer;
  }
}
.tools-item {
  display: flex;
  margin-right: 20px;
  .tools_item {
    width: 50px;
    .tools_item_leftImg {
      width: 50px;
      height: 50px;
    }
    .tools_item_leftWord {
      text-align: center;
      font-size: 12px;
      font-family: Source Han Sans CN;
      font-weight: bold;
      color: #ffffff;
    }
  }
  .tools_item_right {
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-left: 20px;
    .tools_item_rightImg {
      height: 8px;
      width: 45px;
    }
  }
}
.login {
  margin-left: 30px;
}

.soundRecording {
  display: none;
}
</style>